// Created by plusminus on 22:59:38 - 12.09.2008
package com.talkweb.osmharmony.views.overlay;


import com.talkweb.osmharmony.ResourceTable;
import com.talkweb.osmharmony.util.ResourceHelper;
import ohos.agp.components.AttrSet;
import ohos.agp.components.Component;
import ohos.agp.components.DirectionalLayout;
import ohos.agp.components.Image;
import ohos.app.Context;

public class ItemizedOverlayControlView extends DirectionalLayout {

    // ===========================================================
    // Constants
    // ===========================================================

    // ===========================================================
    // Fields
    // ===========================================================

    protected Image mPreviousButton;
    protected Image mNextButton;
    protected Image mCenterToButton;
    protected Image mNavToButton;

    protected ItemizedOverlayControlViewListener mLis;

    // ===========================================================
    // Constructors
    // ===========================================================

    public ItemizedOverlayControlView(final Context context,
                                      final AttrSet attrs) {
        super(context, attrs);

        this.mPreviousButton = new Image(context);
        this.mPreviousButton
                .setImageElement(ResourceHelper.getElement(context, ResourceTable.Media_previous));

        this.mNextButton = new Image(context);
        this.mNextButton.setImageElement(ResourceHelper.getElement(context, ResourceTable.Media_next));

        this.mCenterToButton = new Image(context);
        this.mCenterToButton.setImageElement(ResourceHelper.getElement(context, ResourceTable.Media_center));

        this.mNavToButton = new Image(context);
        this.mNavToButton
                .setImageElement(ResourceHelper.getElement(context, ResourceTable.Media_navto_small));

        this.addComponent(mPreviousButton, new LayoutConfig(
                LayoutConfig.MATCH_CONTENT,
                LayoutConfig.MATCH_CONTENT));
        this.addComponent(mCenterToButton, new LayoutConfig(
                LayoutConfig.MATCH_CONTENT,
                LayoutConfig.MATCH_CONTENT));
        this.addComponent(mNavToButton, new LayoutConfig(
                LayoutConfig.MATCH_CONTENT,
                LayoutConfig.MATCH_CONTENT));
        this.addComponent(mNextButton, new LayoutConfig(
                LayoutConfig.MATCH_CONTENT,
                LayoutConfig.MATCH_CONTENT));

        initViewListeners();
    }

    // ===========================================================
    // Getter & Setter
    // ===========================================================

    public void setItemizedOverlayControlViewListener(final ItemizedOverlayControlViewListener lis) {
        this.mLis = lis;
    }

    public void setNextEnabled(final boolean pEnabled) {
        this.mNextButton.setEnabled(pEnabled);
    }

    public void setPreviousEnabled(final boolean pEnabled) {
        this.mPreviousButton.setEnabled(pEnabled);
    }

    public void setNavToVisible(final int pVisibility) {
        this.mNavToButton.setVisibility(pVisibility);
    }

    // ===========================================================
    // Methods from SuperClass/Interfaces
    // ===========================================================

    // ===========================================================
    // Methods
    // ===========================================================

    private void initViewListeners() {
        this.mNextButton.setClickedListener(new ClickedListener() {
            @Override
            public void onClick(final Component v) {
                if (ItemizedOverlayControlView.this.mLis != null)
                    ItemizedOverlayControlView.this.mLis.onNext();
            }
        });

        this.mPreviousButton.setClickedListener(new ClickedListener() {
            @Override
            public void onClick(final Component v) {
                if (ItemizedOverlayControlView.this.mLis != null)
                    ItemizedOverlayControlView.this.mLis.onPrevious();
            }
        });

        this.mCenterToButton.setClickedListener(new ClickedListener() {
            @Override
            public void onClick(final Component v) {
                if (ItemizedOverlayControlView.this.mLis != null)
                    ItemizedOverlayControlView.this.mLis.onCenter();
            }
        });

        this.mNavToButton.setClickedListener(new ClickedListener() {
            @Override
            public void onClick(final Component v) {
                if (ItemizedOverlayControlView.this.mLis != null)
                    ItemizedOverlayControlView.this.mLis.onNavTo();
            }
        });
    }

    // ===========================================================
    // Inner and Anonymous Classes
    // ===========================================================

    public interface ItemizedOverlayControlViewListener {
        public void onPrevious();

        public void onNext();

        public void onCenter();

        public void onNavTo();
    }
}
